home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-02-10 | 2.8 KB | 134 lines | [TEXT/MPS ] |
- /*
- File: Utils.cp
-
- Contains: General utilities
-
-
-
- Copyright: © 1998 by Apple Computer, Inc., all rights reserved.
-
- Change History:
-
- 22 Mar 98 gp Created
-
- To Do:
- */
- #include "Utils.h"
-
-
- /*-----------------------------------------------------------------------------*
-
- PStrEqualCaseInsensitive
-
- Desc: Compares two Pascal strings while ignoring case
-
- In: string1 - string to compare
- string2 - string to compare
- Out: none
-
- History:
-
- 22 Mar 98 gp Added.
-
- *-----------------------------------------------------------------------------*/
- Boolean PStrEqualCaseInsensitive( Str255 string1, Str255 string2 )
- {
- short x;
- char c1, c2;
-
- if ( string1[0] != string2[0] )
- return( false );
-
- for ( x=1; x<=string1[0]; x++ )
- {
- c1 = string1[x];
- c2 = string2[x];
- if ( c1 != c2 )
- {
- c1 &= ~32;
- c2 &= ~32;
- if ( (c1>='A') && (c1<='Z') && (c1 != c2) )
- return( false );
- }
- }
- return( true );
- }
-
- /*-----------------------------------------------------------------------------*
-
- AppendPStr
-
- Desc: Copy a PASCAL style string to the source
-
- In: mainStr - string to append to
- addStr - string to append
- Out: none
-
- History:
-
- 22 Mar 98 gp Added.
-
- *-----------------------------------------------------------------------------*/
- void AppendPStr(StringPtr mainStr, StringPtr addStr)
- {
- register short i;
- register unsigned char *pMainStr = (unsigned char *)&mainStr[mainStr[0] + 1];
- register unsigned char *pAddStr = (unsigned char *)&addStr[1];
- register short addLength = (unsigned char)addStr[0];
-
- if (addLength)
- {
- // limit the ultimate length to 255 bytes
- if ( ((unsigned char)mainStr[0] + addLength) > 255)
- addLength = 255 - (unsigned char)mainStr[0];
-
- // do the copy
- for (i = 0; i < addLength; ++i)
- *pMainStr++ = *pAddStr++;
-
- // update the count
- mainStr[0] += addLength;
- }
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- NameRegistryInstalled
-
- Desc: Copies the contents of cell in the list hList into the string
- pointed to by theString. The string is converted to a Pascal-
- style string, with a preceding length byte.
-
- It is assumed that cell is a valid cell, that the cell contains no
- more than 255 characters, and that theString and hList are not nil.
-
-
- In: Pointer to storage for a string.
- Coordinates of cell in list
- Handle to list
-
- Out: String containing copy of cell text
-
- History:
-
- 22 Mar 98 gp Added.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- void GetNameFromCell (StringPtr theString, Cell cell, ListHandle hList)
- {
- short length;
-
- /*
- The maximum length of the string is the size of a Str255, minus the
- length byte…
- */
- length = sizeof(Str255) - 1;
-
- LGetCell((StringPtr)(theString + 1), &length, cell, hList);
-
- /*
- Set the length byte.
- */
- *theString = (unsigned char) length;
- };
-
-